<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters">
        <el-form-item>
          <el-input v-model="filters.keyword" placeholder="关键字" size="small"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getTableData" icon="el-icon-search" size="small">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary"  icon="el-icon-plus" size="small"  v-on:click="add" >新增</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="tableData" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55" >
      </el-table-column>
      <el-table-column prop="id" label="id" width="160" align="center" >
      </el-table-column>
      <el-table-column prop="userId" label="用户"  width="100"align="center"  >
      </el-table-column>
      <el-table-column prop="ip" label="ip" width="100" align="center" >
      </el-table-column>
      <el-table-column prop="text" label="拉黑原因" width="100" align="center" >
      </el-table-column>

      <el-table-column label="操作"  >
        <template scope="scope">
          <el-button type="danger" size="small" @click="del(scope.row)" icon="el-icon-remove">移出黑名单</el-button>

        </template>
      </el-table-column>
    </el-table>

    <!--工具条-->
    <!--工具条-->
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0" icon="el-icon-remove" size="small">批量删除</el-button>
      <el-pagination layout="prev, pager, next" @current-change="handleCurrentChange" :page-size="20" :total="total" style="float:right;">
      </el-pagination>
    </el-col>
    <!--黑名单弹出框
    -->
    <el-dialog
        title="加入黑名单"
        :visible.sync="dialogVisible"
        width="30%"
        :before-close="handleClose">
      <el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">

        <el-form-item label="用户" prop="userId">
          <el-input v-model="editForm.userId" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="ip" prop="ip">
          <el-input v-model="editForm.ip" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="editForm.phone" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="拉黑原因" prop="email">
          <el-input v-model="editForm.text" auto-complete="off"></el-input>
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
  </section>
</template>

<script>

export default {
  data() {
    return {
      dialogVisible: false,
      filters: {
        keyword: ''
      },
      tableData: [],
      totals: '',
      pageSize:10,
      currentPage: 1,
      listLoading: false,
      sels:[],
      editForm:{
        text: '',
        phone:null,
        ip: '',
        userId: null,
      },

    }

  },
  methods: {
    //新增对话框
    confirm(){
      var par= this.editForm
      this.$http.post("/common/messageSms/add",par).then(res=>{
        if (res.data.success == true){
          alert("操作成功")
          this.dialogVisible = false;
        }else {
          alert(res.data.message)
          this.dialogVisible = false;
        }
        this.getTableData();
      }).catch(res=>{
        this.$message({ message: "服务不可用，稍后重试["+error.message+"]", type: 'error' });

      })
    },

    //新增黑名单  弹出对话框
    add(row){
      this.editForm.text=""
      this.editForm.phone=''
      this.dialogVisible=true
    },

    selsChange(sels){
      this.sels = sels;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.getTableData();
    },
    //获取用户列表
    getTableData() {
      let para = {
        pageSize: this.pageSize,
        currentPage: this.currentPage,
        keyword: this.filters.keyword,
      };

      this.listLoading = true; //显示加载圈
      this.$http.post("/common/backlist/pagelist",para).then(result=>{
        this.total = result.data.total;
        this.tableData = result.data.data.rows;
        this.listLoading = false;  //关闭加载圈
      }).catch(error => {
        this.listLoading = false;
        this.$message({ message: "数据加载失败["+error.message+"]", type: 'error' });

      })
    },
    edit(){
      this.$message({ message: "功能未开放", type: 'error' });
    },
    del(row){
      this.$http.delete("/common/messageSms/del/"+row.id).then(res=>{
        var success=res.data.success
        if (success==true){
          this.$message({ message: "删除成功", type: 'success' });
        }else {
          this.$message({ message: "删除失败", type: 'error' })
        }
        this.getTableData();
      }).catch(res=>{
        this.$message({ message: "系统异常，稍后重试", type: 'error' });

      })
    },
    batchRemove(){
      this.$message({ message: "功能未开放", type: 'error' });
    },

  },
  mounted() {
    this.getTableData();
  }
}

</script>

<style scoped>

</style>